home *** CD-ROM | disk | FTP | other *** search
- Path: news.clark.net!not-for-mail
- From: gusty@clark.net (Harlan Messinger)
- Newsgroups: comp.lang.c++
- Subject: Re: cout stupidity
- Date: 11 Jan 1996 20:13:36 GMT
- Organization: Clark Internet Services, Inc., Ellicott City, MD USA
- Distribution: world
- Message-ID: <4d3r1g$uj@clarknet.clark.net>
- References: <4d321g$eal@calvin.st-and.ac.uk>
- NNTP-Posting-Host: explorer.clark.net
- Mime-Version: 1.0
- Content-Type: TEXT/PLAIN; charset=ISO-8859-1
- Content-Transfer-Encoding: 8bit
- X-Newsreader: TIN [UNIX 1.3 950726BETA PL0]
-
- Keith Sibson (ks2@st-and.ac.uk) wrote:
- :
- : #include <iostream.h>
- :
- : int count=10;
- :
- : main()
- : {
- : for(i=0;i<cout;i++) {.....}
- : return(0);
- : }
- :
- : Why does this stupidity compile? (BCC 4.5)
- :
- : Surely cout is of type ostream? Either there is a dubious operator< that
- : takes an int and ostream, or there is some wacky automatic conversions going
- : on. Does an ostream cast to an int that is the stream position?
- :
- : Keith.
- :
-
- An overload in the ios base class appears to be the source of this. In
- VC++'s ios.h, we have
-
- operator void *() const { if(state&(badbit|failbit) )
- return 0; return (void *)this; }
-
- I guess this allows an ios object to be implicitly recast as a void
- pointer, to the object if it's valid or to NULL otherwise. This allows
- one to use the object iself as the control expression in if statements
- and so forth:
-
- if (my_ios) { ... } /* Execute this code only if my_ios is valid */
-
- They also overload the ! operator,
-
- inline int ios::operator!() const { return state&(badbit|failbit); }
-
- allowing
-
- if (!my_ios) { ... }
-
-
-
-